package com.gitee.wsl.io.buffer.ext


import com.gitee.wsl.io.buffer.ByteBuffer


/**
 * Moves all bytes in `this` buffer to a newly created buffer with the optionally specified [size]
 *
 * [Report a problem](https://ktor.io/feedback/?fqname=io.ktor.util.copy)
 */
fun ByteBuffer.copy(size: Int = remaining): ByteBuffer {
    return ByteBuffer.allocate(size).apply {
        this@copy.slice().moveTo(this@apply)
        clear()
    }
}

